package com.neuedu.yyzx.controller;

import com.neuedu.yyzx.common.Ret;
import com.neuedu.yyzx.config.security.SecurityUtils;
import com.neuedu.yyzx.po.User;
import com.neuedu.yyzx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 金山
 * 项目：yyzx
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2025/4/2714:27
 */
@RestController
@RequestMapping("/profile")
public class ProfileController {

    @Autowired
    SecurityUtils securityUtils;

    @Autowired
    UserService userService;


    @RequestMapping("/updateAvatar/{id}")
    public Ret<Boolean> updateAvatar(@PathVariable String id) {

        // 根据token获取用户id
        User userInfo = securityUtils.getUserInfo();
        Long userId = userInfo.getId();

        // 根据用户id获取最新的  用户谁
        User user = userService.getById(userId);
        // 设置用户头像地址
        user.setAvatar(id);

        return Ret.ok(userService.updateById(user));

    }


}
